package com.gin.no_gay_alliance.fragment.item;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gin.nga.response.body.nuke.ItemBody;
import com.gin.no_gay_alliance.app.MyApplication;
import com.gin.no_gay_alliance.callback.Callback;
import com.gin.no_gay_alliance.customview.ItemView;
import com.gin.no_gay_alliance.databinding.FragmentInventoryBinding;
import com.gin.no_gay_alliance.param.ItemParam;

/**
 * 道具库存
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/7 16:28
 **/
public class InventoryFragment extends BaseItemFragment<FragmentInventoryBinding> implements Callback<ItemBody> {

    @Override
    protected ItemView.Params buildParams(ItemParam param) {
        if (param.isToUser()) {
            return new ItemView.Params(ItemView.Action.USE, param.userId);
        } else if (param.isToReply()) {
            return new ItemView.Params(ItemView.Action.USE, param.topicId, param.replyId);
        } else {
            return new ItemView.Params(ItemView.Action.CHECK);
        }
    }

    /**
     * 提供布局中的 RecyclerView
     *
     * @return RecyclerView
     */
    @NonNull
    @Override
    protected RecyclerView initRecyclerView() {
        return b.recyclerView;
    }

    /**
     * 发送请求
     *
     * @param more 是否为加载更多, 否时从第一页开始
     */
    @Override
    protected void sendRequest(boolean more) {
        MyApplication.app.managerFactory.getItemInventoryManager().itemInventory(false, page, this);
    }

    /**
     * onCreateView 的后续操作
     */
    @Override
    protected void onCreateView() {
        super.onCreateView();
    }

    @Override
    public void onResume() {
        super.onResume();
        load(false);
    }

    public static InventoryFragment newInstance(ItemParam param) {
        InventoryFragment fragment = new InventoryFragment();
        fragment.setItemParam(param);
        return fragment;
    }

}
